using System;
using Ninject;
using ODSearchEngine;
using System.Collections.Generic;
using ServiceStack.ServiceClient;
using ODSWebService.DTO.Requests;
using ODSWebService.DTO.Responses;
using ODSDataExtraction;
using System.IO;

namespace Testing
{
	class MainClass
	{
		static ServiceStack.Service.IServiceClient client = 
				new ServiceStack.ServiceClient.Web.JsonServiceClient("http://127.0.0.1:8080/servicestack/");
		public static void IndexData(Dictionary<string, string> data)
		{
			IndexRequest request = new IndexRequest();			
			request.Data = data;
			var response = client.Send<IndexResponse>(request);
			Console.WriteLine ("Indexation requested. Result: {0}", response);
		}
		
		public static void SearchData()
		{
			ODSWebService.DTO.Requests.SearchRequest request = new ODSWebService.DTO.Requests.SearchRequest();
			request.Keys = new string[] {"FileName", "FileContent", "FilePath"};
			while(true)
			{
				Console.WriteLine ("Your query: ");
				request.Query = Console.ReadLine();
				var resp = client.Send<SearchResponse>(request);
				Console.WriteLine(resp);
				foreach(var r in resp.Results)
				{
					Console.WriteLine(r);
					foreach(var d in r.Data.Keys)
					{
						Console.WriteLine ("{0} : {1}", d, r.Data[d]);
					}
				}
			}
		}
		public static void Main (string[] args)
		{		
			log4net.Config.XmlConfigurator.Configure();			
			ExtractorsPipeline pipe = new ExtractorsPipeline();
			FileInfo fi = new FileInfo("./Untitled.txt");			
			Dictionary<string, string> data = pipe.ExtractData(fi) as Dictionary<string, string>;
			foreach(var item in data)
			{
				Console.WriteLine ("Extracted {0}:{1}", item.Key, item.Value);
			}
			IndexData(data);
			SearchData();
			
		}
	}
}

